﻿//--------------------------------------------------------------------------
// 
//  Copyright (c) Chili Software.  All rights reserved. 
// 
//  File: IMethodHandler.cs
//
//  Description: Interface that is implemented to handle special SQL methods.
// 
//--------------------------------------------------------------------------

using System;
using System.Linq.Expressions;
using System.Reflection;

namespace Chili.Opf3.Linq
{
	/// <summary>
	/// This interface is implemented by classes to handle special SQL methods. Examples on 
	/// how to implement this interface are found in <see cref="QueryUtilityMethodsHandler">QueryUtilityMethodsHandler</see>
	/// and <see cref="StringMethodsHandler">StringMethodsHandler</see>.
	/// </summary>
	public interface IMethodHandler
	{
		/// <summary>
		/// Returns whether the class can handle the given method.
		/// </summary>
		/// <param name="method">The method to handle.</param>
		/// <param name="type">The type on which the method is defined.</param>
		bool CanHandle(MethodInfo method, Type type);

		/// <summary>
		/// Returns the method call converted in an SQL compatible string.
		/// </summary>
		/// <param name="expression">The expression that is converted to the SQL compatible string. This expression
		/// contains the method that has been called with all the arguments and eventually sub expressions.</param>
		/// <param name="args">Holds a utility class that contains different methods to be used during string compilation.</param>
		string Handle(MethodCallExpression expression, MethodHandlerArgs args);
	}
}
